package com.zjw.algorithm.ready1;

public class _斐波拉契数列解法 {


    public int fib(int n) {
        if (n == 0) {
            return 0;

        }

        if (n == 1) {
            return 1;
        }

        int[] dp = new int[3];

        dp[0] = 0;
        dp[1] = 1;

        int count = 2;

        while (count <= n) {
            dp[count % 3] = (dp[(count - 1) % 3] + dp[(count - 2) % 3]) % 1000000007;
            count++;
        }

        return dp[(count - 1) % 3];
    }
}
